package com.dys.testcomparable09;

import java.util.Comparator;

/**
 * @className: com.dys.testcomparable09.Person
 * @description: com.dys.testcomparable09
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/08/08 下午8:23
 */
public class Person {
    private String name;
    private int age;
    private double height;

    public Person(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", height=" + height +
                '}';
    }
}

class Comparisons1 implements Comparator<Person> {

    @Override
    public int compare(Person o1, Person o2) {
        // 1.按照年龄进行比较
        return o1.getAge() - o2.getAge();
    }
}

class Comparisons2 implements Comparator<Person> {
    @Override
    public int compare(Person o1, Person o2) {
        // 2.按照身高进行比较
        return ((Double) (o1.getHeight())).compareTo(((Double) (o2.getHeight())));
    }
}

class Comparisons3 implements Comparator<Person> {

    @Override
    public int compare(Person o1, Person o2) {
        // 1.年龄相同,比较身高,年龄不同,比较年龄
        if (o1.getAge() - o2.getAge() == 0) {
            return ((Double) (o1.getHeight())).compareTo(((Double) (o2.getHeight())));
        } else {
            return o1.getAge() - o2.getAge();
        }
    }
}